package com.cqw;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;

import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class OrderShipment {

    @ApiModelProperty(value = "物流状态")
    private String status;

    @ApiModelProperty(value = "备注")
    private String remark;

    private List<OrderShipmentNode> nodes;

    @ApiModelProperty(value = "更新时间")
    private Date updatedTime;

    public OrderShipment() {
    }

    public static OrderShipment getLatest(OrderShipment oldShipment, OrderShipment newShipment) {
        if (oldShipment == null) {
            return newShipment;
        }

        if (oldShipment.nodes == null) {
            return newShipment;
        }

        if (oldShipment.nodes.size() == 0) {
            return newShipment;
        }

        if (newShipment.nodes == null || newShipment.nodes.size() == 0) {
            return oldShipment;
        }

        newShipment.nodes.sort(Collections.reverseOrder(Comparator.comparing(OrderShipmentNode::getTime)));
        return newShipment.nodes.get(0).getTime().after(oldShipment.nodes.get(0).getTime()) ? newShipment : oldShipment;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public List<OrderShipmentNode> getNodes() {
        return nodes;
    }

    public void setNodes(List<OrderShipmentNode> nodes) {
        this.nodes = nodes;
    }

    public Date getUpdatedTime() {
        return updatedTime;
    }

    public void setUpdatedTime(Date updatedTime) {
        this.updatedTime = updatedTime;
    }
}